package com.cz.common.utils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.apache.cxf.transport.http.HTTPConduit;
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;


import java.util.*;

/**
 * *接口调用工具类
 * @author clove
 * @create: 2020-01-15
 */
public class SellMasterUtil {

   public static String wsdlUrl="http://192.168.0.8:7100/Service.asmx?WSDL";
   public static String code="7F20626E185E9B28";

   public static List<String> sellMasterCodeList=new ArrayList<>();


   public static Map getSellMaster(String startDate){
       //创建动态客户端
       JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance();
       String [] options = { "autoNameResolution" };
       factory.setSchemaCompilerOptions(options);
       Client client = factory.createClient(wsdlUrl);
       // 需要密码的情况需要加上用户名和密码
       //client.getOutInterceptors().add(new ClientLoginInterceptor(USER_NAME,PASS_WORD));
       HTTPConduit conduit = (HTTPConduit) client.getConduit();
       HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
       httpClientPolicy.setConnectionTimeout(10000);  //连接超时
       httpClientPolicy.setAllowChunking(false);    //取消块编码
       httpClientPolicy.setReceiveTimeout(120000);     //响应超时
       conduit.setClient(httpClientPolicy);
       try {
           JSONObject parameters = new JSONObject();
           parameters.put("StartDate",startDate );
           Object[] objects = new Object[0];
           // invoke("方法名",参数1,参数2,参数3....);
           objects = client.invoke("GetSellMasterByCode", code,parameters.toJSONString());
           Map maps = (Map) JSON.parse(objects[0].toString());
           String resultCode=maps.get("ResultCode").toString();
           if(resultCode.equals("100")){
                return maps;
           }else {
               System.err.println("订单接口错误------"+maps.get("ResultDesc"));
           }
       } catch (Exception e) {
           e.printStackTrace();
       }
       return null;
   }

}